﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Threading;
using virtuaPol.Controls;

namespace virtuaPol.Main
{
    public class UIDispatcher
    {

        private Dispatcher Dispatcher { get; set; }

#region Hooks

        public event EventHandler<ShowMessageHookArgs> ShowMessageHook;
        public event EventHandler<PlayVideoHookArgs> PlayVideoHook;
        public event EventHandler<PlayAudioHookArgs> PlayAudioHook;

        private delegate void AskUserDelegate(string msg);
        
#endregion

        public UIDispatcher(Dispatcher dispatcher)
        {
            Dispatcher = dispatcher;
        }

        public void ShowMessage(string message)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, ShowMessageHook, this, new ShowMessageHookArgs(message));
        }

        public bool AskUserYesNo(string message)
        {
            bool answer = false;
            Dispatcher.Invoke(DispatcherPriority.Normal, (AskUserDelegate)delegate(string msg)
            {
                AskUserDlg dlg = new AskUserDlg(msg);
                dlg.ShowDialog();
                answer = dlg.Answer;
            }, message);

            return answer;
        }

        public void PlayVideo(string file, bool fullscreen)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, PlayVideoHook, this, new PlayVideoHookArgs(file, fullscreen));
        }

        public void PlayAudio(string file)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, PlayAudioHook, this, new PlayAudioHookArgs(file));
        }
    }
}
